<?php include 'header.php'; ?>
		<?php if(isset($_SESSION['user'])):  ?>
			<meta http-equiv="refresh" content="0;URL=home.php">
		<?php else: ?>
		<h2>Welcome to the SIGBio Dissertation Abstract Repository</h2>
		In order to use the archive, please login using your ACM username and password in the fields below.<br><br>
		<h3>Login</h3>
	<?php 
		$username = $password =  $errMsg = "";
		if ($_SERVER["REQUEST_METHOD"] == "POST")
		{
			$username = $_POST["username"];
			$password = $_POST["password"];
			$response = trim(file_get_contents('https://campus.acm.org/public/memlogin/ckLogin.cfm?ckmem&uname=' . $username . '&pword=' . $password ));
			
			if ($response == "YES")
			{
				$_SESSION["user"] = $username;
				echo "<meta http-equiv=\"refresh\" content=\"0;URL=home.php\">";
			}
			else if ($response == "NO")
				$errMsg = "Invalid username or password.";
			else
				$errMsg =  "Something went wrong.";
		}
		echo " <b> " . $errMsg . "</b><br>";
	?>
	
	<form method="post" action="<?php echo htmlspecialchars($_SERVER["REQUEST_URI"]);?>">
		Username: <input type = "text" name = "username" value = "<?php echo $username; ?>"><br>
		Password: <input type = "password" name = "password" value = ""><br><br>
		<input type = "submit" name = "sendCredentials" value = "Login">
	</form><br><br><br><br>
	Don't have an ACM Login? <a href="http://campus.acm.org/public/qj/quickjoin/interim.cfm?promo=PWEBTOP">Register/Join</a><br><br>
	If you have any questions, feel free to contact Dr. Mikler at <a href="mailto:mikler@acm.org">mikler@acm.org</a>
	<?php endif; ?>
<?php include 'footer.php'; ?>